package com.edu.imau.FixedParking;

import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/FixedAdd")
public class FixedAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String fixed_id = request.getParameter("fixed_id");
        String fixed_name =request.getParameter("fixed_name");
        String fixed_age =request.getParameter("fixed_age");
        String fixed_brand =request.getParameter("fixed_brand");
        String fixed_cnumber =request.getParameter("fixed_cnumber");
        String fixed_pnumber =request.getParameter("fixed_pnumber");
        String fixed_state =request.getParameter("fixed_state");
        //2 调用model
        if(fixed_id == null||fixed_id.equals("")){
            Fixed fixed = new Fixed(-1,fixed_name,fixed_age,fixed_brand,
                    fixed_cnumber,fixed_pnumber,fixed_state);
            dao.addFixed(fixed);
        }else{
            Fixed fixed = new Fixed(Integer.parseInt(fixed_id),fixed_name,fixed_age,fixed_brand,
                    fixed_cnumber,fixed_pnumber,fixed_state);
            dao.updateFixed(fixed);
        }
        //3 数据交给View
        response.sendRedirect("Fixed.jsp");
    }
}
